<?php
/**
 * Created by JetBrains PhpStorm.
 * User: User
 * Date: 9/21/12
 * Time: 6:01 PM
 * To change this template use File | Settings | File Templates.
 */

class Db_Payment
{
    public static function getPaymentByCartId($cart_id, $call_pos='') {
        return DB::fetch("SELECT * FROM cart_payment WHERE cart_id=$cart_id", false, false, $call_pos);
    }

    public static function create($cart_id, $data=array()) {
        $data['cart_id'] = $cart_id;
        $data['user_id'] = User::id();
        $data['user_email'] = User::user_email();
        $data['time'] = TIME_NOW;
        $data['order_code'] = Db_Booking::random_string('alpha', 3+(max(0,3-strlen($cart_id)))).$cart_id;
        return DB::insert('cart_payment', $data);
    }

    public static function update($id, $data) {
        $data['user_modify'] = User::id();
        $data['time_modify'] = TIME_NOW;
        return DB::update_id('cart_payment', $data, $id);
    }

    public static function sync($id) {

    }

    /*public static function random_string($length=32) {
        $secret_code = '';
        for($i=0; $i<$length; $i++) {
            switch(rand(0,2)) {
                case 0:
                    $secret_code .= chr(rand(48, 57));
                    break;
                case 1:
                    $secret_code .= chr(rand(65, 90));
                    break;
                case 2:
                    $secret_code .= chr(rand(97, 122));
            }
        }
        return $secret_code;
    }*/
}